<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//服务器的动态网页中禁止缓存
response.setHeader("Pragma","No-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.setDateHeader("Expires", 0);  
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Allocator Information Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function submitForm() {
  		var assignMeterUID = "<s:property value='assignMeterUID' />";
  		//表单信息
  		var projectID = $("select[name='assignMeter.projectID']").val();
  		var communityID = $("select[name='assignMeter.communityID']").val();
  		var buildingID = $("select[name='assignMeter.buildingID']").val();
  		var roomId = $("select[name='assignMeter.roomId']").val();
  		var concentratorID = $("select[name='assignMeter.concentratorID']").val();
  		var heatSinkID = $("select[name='assignMeter.heatSinkID']").val();
  		var seriousNum = $("input[name='seriousNum']").val();
  		var model = $("input[name='model']").val();
  		var type = $("input[name='type']").val();
  		var recordMan = $("input[name='recordMan']").val();
  		var installMan = $("input[name='installMan']").val();
  		var installDate = $("input[name='installDate']").val();
  		var softVersion = $("input[name='softVersion']").val();
  		var hardVersion = $("input[name='hardVersion']").val();
  		var installPosition = $("input[name='installPosition']").val();
  		var isNormal = $("select[name='assignMeter.isNormal']").val();
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"beshs/assignMeterActionJson!saveOrUpdateMeterInfo.do?date="+new Date(), {
  			"assignMeter.id": assignMeterUID,
  			"assignMeter.projectID": projectID,
  			"assignMeter.communityID": communityID,
  			"assignMeter.buildingID": buildingID,
  			"assignMeter.roomId": roomId,
  			"assignMeter.concentratorID": concentratorID,
  			"assignMeter.heatSinkID": heatSinkID,
  			"assignMeter.seriousNum": seriousNum,
  			"assignMeter.model": model,
  			"assignMeter.type": type,
  			"assignMeter.recordMan": recordMan,
  			"assignMeter.installMan": installMan,
  			"assignMeter.installDate": installDate,
  			"assignMeter.softVersion": softVersion,
  			"assignMeter.hardVersion": hardVersion,
  			"assignMeter.installPosition": installPosition,
  			"assignMeter.isNormal": isNormal,
  			"assignMeter.remark": $.trim(remark)
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Successful Operation！", function() {
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["c_content_content"].location = path + "beshs/assignMeterAction!queryAssignMeterPage.do?date"+new Date();
  					parent.layer.close(index);
  				});
  			} else {
  				Dialog.alert(data.msg);
  			}
  		});
  	}
  	
  	$(function(){
		$("form[name='assignMeterForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			ajaxPost:true,
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
				submitForm();
				return true; //这里明确return false的话表单将不会提交
			}
		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#" name="assignMeterForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      			<tr>
          			<th>Project：</th>
          			<td><s:select name="assignMeter.projectID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"
          					datatype="*" nullmsg="Please select the project！" errormsg="Please select the project！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>District：</th>
          			<td>
          				<script type="text/javascript">
		      				function reloadCommunitys(projectUID, communityUID) {
		      					$("select[name='assignMeter.communityID']").children("option").slice(1).remove();
		      					if(projectUID!=null && projectUID!="") {
		      						$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
		      							projectUID: projectUID
		      						}, function(data){
		      							for(var index=0; index<data.length; index++) {
		      								if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
			        							$("select[name='assignMeter.communityID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
			        						} else {
			        							$("select[name='assignMeter.communityID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
			        						}
		      							}
		      						});
		      					}
		      				}
		      					
		      				$(function() {
		      					$("select[name='assignMeter.projectID']").change(function(){
				        			var projectUID = $(this).val();
				        			var communityUID = $("select[name='assignMeter.communityID']");
				        			reloadCommunitys(projectUID, communityUID);
				        		});
		      				});
		      			</script>
		      			<s:select name="assignMeter.communityID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel"
		      				datatype="*" nullmsg="Please select the district！" errormsg="Please select the district！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Building：</th>
          			<td>
          				<script type="text/javascript">
				       		function reloadBuildings(projectUID, communityUID, buildingUID) {
			        			$("select[name='assignMeter.buildingID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/buildingActionJson!queryBuildingsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(buildingUID!=null && buildingUID!="" && buildingUID==data[index].id) {
	        								$("select[name='assignMeter.buildingID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].buildingName+"</option>");
	        							} else {
	        								$("select[name='assignMeter.buildingID']").append("<option value='"+data[index].id+"'>"+data[index].buildingName+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		
			        		$(function(){
			        			$("select[name='assignMeter.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        			
			        			$("select[name='assignMeter.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				reloadBuildings(projectUID, communityUID, buildingUID);
			        			});
			        		});
			       		</script>
			       		<s:select name="assignMeter.buildingID" list="buildingList" listKey="id" listValue="buildingName" headerKey="" headerValue="Please select" cssClass="s_sel"
			       			datatype="*" nullmsg="Please select the building！" errormsg="Please select the building！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>Heat User：</th>
          			<td>
          				<script type="text/javascript">
			        		function reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID) {
			        			$("select[name='assignMeter.roomId']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/heatRoomActionJson!queryHeatRoomsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID,
			        				buildingUID: buildingUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(heatRoomUID!=null && heatRoomUID!="" && heatRoomUID==data[index].id) {
	        								$("select[name='assignMeter.roomId']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].houseNo+"</option>");
	        							} else {
	        								$("select[name='assignMeter.roomId']").append("<option value='"+data[index].id+"'>"+data[index].houseNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		$(function(){
			        			$("select[name='assignMeter.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='assignMeter.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        			
			        			$("select[name='assignMeter.buildingID']").change(function(){
			        				var buildingUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				reloadHeatRooms(projectUID, communityUID, buildingUID, heatRoomUID);
			        			});
			        		});
			        	</script>
						<s:select name="assignMeter.roomId" list="heatRoomList" listKey="id" listValue="houseNo" headerKey="" headerValue="Please select" cssClass="s_sel"
							datatype="*" nullmsg="Please select the heat user！" errormsg="Please select the heat user！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Concentrator No.</th>
        			<td>
        				<script type="text/javascript">
				       		function reloadConcentrators(projectUID, communityUID, concentratorUID) {
			        			$("select[name='assignMeter.concentratorID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/concentratorActionJson!queryConcentratorsByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(concentratorUID!=null && concentratorUID!="" && concentratorUID==data[index].id) {
	        								$("select[name='assignMeter.concentratorID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].concentratorNo+"</option>");
	        							} else {
	        								$("select[name='assignMeter.concentratorID']").append("<option value='"+data[index].id+"'>"+data[index].concentratorNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		
			        		$(function(){
			        			$("select[name='assignMeter.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var concentratorUID = $("select[name='assignMeter.concentratorID']").val();
			        				reloadConcentrators(projectUID, communityUID, concentratorUID);
			        			});
			        			
			        			$("select[name='assignMeter.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var concentratorUID = $("select[name='assignMeter.concentratorID']").val();
			        				reloadConcentrators(projectUID, communityUID, concentratorUID);
			        			});
			        		});
        				</script>
	        			<s:select name="assignMeter.concentratorID" list="concentratorList" listKey="id" listValue="concentratorNo" headerKey="" headerValue="Please select" cssClass="s_sel"
	        				datatype="*" nullmsg="Please select the concentrator no.！" errormsg="Please select the concentrator no.！"></s:select>
	            			&nbsp;<span style="color:#FF0000;">*</span>
	            		<div class="Validform_checktip"></div></td>
	            	<th>Radiator No.</th>
        			<td>
        				<script type="text/javascript">
	        				function reloadHeatSinkers(projectUID, communityUID, buildingUID, heatRoomUID, heatSinkerUID) {
			        			$("select[name='assignMeter.heatSinkID']").children("option").slice(1).remove();
			        			$.getJSON(path+"beshs/sinkActionJson!queryBindableSinkersByBelongs.do?date="+new Date(), {
			        				projectUID: projectUID,
			        				communityUID: communityUID,
			        				buildingUID: buildingUID,
			        				heatRoomUID: heatRoomUID
			        			}, function(data) {
			        				for(var index=0; index<data.length; index++) {
			        					if(heatSinkerUID!=null && heatSinkerUID!="" && heatSinkerUID==data[index].id) {
	        								$("select[name='assignMeter.heatSinkID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].sinkNo+"</option>");
	        							} else {
	        								$("select[name='assignMeter.heatSinkID']").append("<option value='"+data[index].id+"'>"+data[index].sinkNo+"</option>");
	        							}
			        				}
			        			});
			        		}
			        		$(function(){
			        			$("select[name='assignMeter.projectID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				var heatSinkerUID = $("select[name='assignMeter.heatSinkID']").val();
			        				reloadHeatSinkers(projectUID, communityUID, buildingUID, heatRoomUID, heatSinkerUID);
			        			});
			        			
			        			$("select[name='assignMeter.communityID']").change(function(){
			        				var communityUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				var heatSinkerUID = $("select[name='assignMeter.heatSinkID']").val();
			        				reloadHeatSinkers(projectUID, communityUID, buildingUID, heatRoomUID, heatSinkerUID);
			        			});
			        			
			        			$("select[name='assignMeter.buildingID']").change(function(){
			        				var buildingUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var heatRoomUID = $("select[name='assignMeter.roomId']").val();
			        				var heatSinkerUID = $("select[name='assignMeter.heatSinkID']").val();
			        				reloadHeatSinkers(projectUID, communityUID, buildingUID, heatRoomUID, heatSinkerUID);
			        			});
			        			
			        			$("select[name='assignMeter.roomId']").change(function(){
			        				var heatRoomUID = $(this).val();
			        				var projectUID = $("select[name='assignMeter.projectID']").val();
			        				var communityUID = $("select[name='assignMeter.communityID']").val();
			        				var buildingUID = $("select[name='assignMeter.buildingID']").val();
			        				var heatSinkerUID = $("select[name='assignMeter.heatSinkID']").val();
			        				reloadHeatSinkers(projectUID, communityUID, buildingUID, heatRoomUID, heatSinkerUID);
			        			});
			        		});
        				</script>
	        			<s:select name="assignMeter.heatSinkID" list="heatSinkerList" listKey="id" listValue="sinkNo" headerKey="" headerValue="Please select" cssClass="s_sel"
	        				datatype="*" nullmsg="Please select the radiator no.！" errormsg="Please select the radiator no.！"></s:select>
	            			&nbsp;<span style="color:#FF0000;">*</span>
	            		<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Allocator No.：</th>
          			<td><input name="seriousNum" type="text" class="s_input" value="<s:property value='assignMeter.seriousNum' />" 
          					ajaxurl="<%=basePath%>beshs/formAsyncValidateActionJson!validSeriousNumUnique.do?entityUuid=<s:property value='assignMeter.id' />"
          					datatype="/^[0-9a-zA-Z]{1,40}$/" sucmsg="Allocator No. Verification Passed！" nullmsg="Please enter Allocator No.！" errormsg="Allocator No. only can be composed of letters,numbers and dashes within 1~40 characters！"/>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Allocator No. only can be composed of letters,numbers and dashes within 1~40 characters！</div></td>
            		<th>Allocator Model：</th>
          			<td>
          				<input name="model" type="text" class="s_input" value="<s:property value='assignMeter.model' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" ignore="ignore" errormsg="Allocator Model only can be composed of letters,numbers and dashes within 2~25 characters！"/>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Type：</th>
          			<td>
          				<input name="type" type="text" class="s_input" value="<s:property value='assignMeter.type' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" ignore="ignore" errormsg="Type only can be composed of letters,numbers and dashes within 2~25 characters！"/>
            			<div class="Validform_checktip"></div></td>
            		<th>Recorder：</th>
          			<td>
          				<input name="recordMan" type="text" class="s_input" value="<s:property value='assignMeter.recordMan' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" ignore="ignore" errormsg="Recorder only can be composed of letters,numbers and dashes within 2~25 characters！"/>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Installation personnel：</th>
          			<td>
          				<input name="installMan" type="text" class="s_input" value="<s:property value='assignMeter.installMan' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" ignore="ignore" errormsg="Installation personnel only can be composed of letters,numbers and dashes within 2~25 characters！"/>
            			<div class="Validform_checktip"></div></td>
            		<th>Installation Time：</th>
          			<td>
          			<input id="meter_intallDate" name="installDate" class="Wdate" value="<s:date name='installDate' format='yyyy-MM-dd' nice='false' />" errormsg="Please enter date and time in correct format such as--2014-07-19！" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})" />
          			
<%--           				<input name="installDate" type="text" class="s_input" id="meter_intallDate" value="<s:date name='assignMeter.installDate' format='yyyy-MM-dd' nice='false' />" onclick="selectDate(this,'yyyy-MM-dd')"  --%>
<!--           					datatype="/^(\d{4})-(\d{1,2})-(\d{1,2})$/" ignore="ignore" errormsg="Please enter date and time in correct format such as--2014-07-19！" readonly/> -->
<%--           				<img src="<%=basePath%>resources/datepicker/calendar.jpg" onclick="txtSelectDate('meter_intallDate','yyyy-MM-dd')"/> --%>
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Allocator Software Version No.：</th>
          			<td>
          				<input name="softVersion" type="text" class="s_input" value="<s:property value='assignMeter.softVersion' />" 
          					datatype="s1-25" ignore="ignore" errormsg="Allocator Software Version No. only can be composed of letters,numbers and dashes within 1~25 characters！"/>
            			<div class="Validform_checktip"></div></td>
            		<th>Allocator Hardware Version No.：</th>
          			<td>
          				<input name="hardVersion" type="text" class="s_input" value="<s:property value='assignMeter.hardVersion' />" 
          					datatype="s1-25" ignore="ignore" errormsg="Hardware Version No. only can be composed of letters,numbers and dashes within 1~25 characters！" />
            			<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
            		<th>IsNormal：</th>
          			<td>
          				<s:select name="assignMeter.isNormal" list="#{1:'Normal', 2:'Abnormal'}" headerKey="" headerValue="Please Select" cssClass="s_sel"></s:select>
          			</td>
          			<th>Installation Position:</th>
          			<td><input name="installPosition" class="s_input" value="<s:property value='assignMeter.installPosition'/>"/></td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="remark" cols="45" rows="3"
          					datatype="*1-200" ignore="ignore" errormsg="Invalid input!  please input valid content ,no more than 200pcs character">
          					<s:property value='assignMeter.remark' /></textarea>
          				</td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
